package chainOfResponsibility;

import gameBasics.GameObject;
import object.Wall;
import tank.EnemyTank;
import tank.Tank;

public class ETankWallCollider implements Collider{

    /**
     * 敌对坦克与墙碰撞
     * @param o1 敌对坦克对象
     * @param o2 墙对象
     */
    @Override
    public boolean collide(GameObject o1, GameObject o2) {
        if(o1 instanceof EnemyTank enemyTank && o2 instanceof Wall wall){
            collideWith(enemyTank, wall);
        } else if (o1 instanceof Wall && o2 instanceof Tank) {
            collide(o2, o1);
        }

        return true;
    }

    /**
     * 敌对坦克与墙的碰撞检测
     * @param enemyTank 敌对坦克对象
     * @param wall 墙对象
     */
    private void collideWith(EnemyTank enemyTank, Wall wall) {
        if (enemyTank.getRectangle().intersects(wall.getRectangle())){
            enemyTank.back();
        }
    }

}
